#!/usr/bin/env python

#Class to allow users to place buildings and such.
#This will be the main class the user uses in a browser.
#Most of the purpose of this class will to be to load a page.
#JS will do the heavy lifting.

#import units
import constants
import inituser
import jinja2
import os
import user
import webapp2

from google.appengine.api import users
#from google.appengine.ext import db
#from lxml import etree
#from pykml.factory import KML_ElementMaker as KML
jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))

class Planner(webapp2.RequestHandler):
    def get(self):
        #Get a user id from the request
        cur_user = users.get_current_user()
        if not cur_user:
            #Shouldn't happen...
            self.response.out.write("Unable to get current user (error 0301)")
            return

        #See if we have a matching user in the datastore
        userobj = user.User.gql("WHERE userID = :1", cur_user).get()

        #Render the template
        templatevars = {"uid":          str(userobj.key()) if userobj else False,
                        "domain":       constants.AppConstants.domain
        }
        template = jinja_environment.get_template('Templates/planner.html')
        self.response.out.write(template.render(templatevars))



app = webapp2.WSGIApplication([
                               ('/planner', Planner)
                               ], debug=True)
